/*
 * @Author: Wushiqi
 * @Descripttion: 路由表改为根据菜单动态加载
 * @Date: 2020-08-06 14:11:31
 * @LastEditor: Wushiqi
 * @LastEditTime: 2021-05-17 11:38:28
 */
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    // 首页
    path: '/',
    component: Layout,
    redirect: '/profile',
    name: 'profile',
    children: [
      {
        path: '/profile',
        component: resolve => (require(['@/views/user/profile'], resolve)),
        name: 'profile',
        meta: { title: '个人中心', icon: 'user', cache: true }
      }

    ]
  },
  {
    path: '*',
    redirect: '/redirect/:path*'
  },
  {
    path: '/redirect',
    name: 'redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: resolve => (require(['@/views/redirect/redirect'], resolve))
      }
    ]
  },
  {
    // 登录页面
    path: '/login',
    name: 'login',
    component: resolve => (require(['@/views/login/login'], resolve)),
    hidden: true
  }
]

const setValues = require('../../public/config')
const createRouter = () => new Router({
  mode: 'history',
  base: setValues.routerBase,
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // 重置 router
}
export default router
